/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PanelLeccionAprendida.java
 *
 * Created on 31-may-2012, 11:37:06
 */
package edu.eam.gruposenior.gestorLEcciones.vista;

import edu.eam.gruposenior.gestorLEcciones.controladores.LeccionController;
import edu.eam.gruposenior.gestorLEcciones.controladores.LoginController;
import edu.eam.gruposenior.gestorLEcciones.controladores.ProyectoController;
import edu.eam.gruposenior.gestorLEcciones.entidades.CategoriaSubcategoria;
import edu.eam.gruposenior.gestorLEcciones.entidades.LeccionAprendida;
import edu.eam.gruposenior.gestorLEcciones.entidades.Proyecto;
import edu.eam.gruposenior.gestorLEcciones.util.LogginManager;
import java.util.Date;
import java.util.List;

/**
 *
 * @author Claudia
 */
public class PanelLeccionAprendida extends javax.swing.JPanel {

    /** Creates new form PanelLeccionAprendida */
    private LeccionAprendida leccion;
    private List<LeccionAprendida> lecciones;
    private LeccionController control;
    private int indiceLeccionActual;
    private LeccionAprendida leccionActual;
    private CategoriaSubcategoria categoria;
    VentanaPrincipal vent;

    public PanelLeccionAprendida(LeccionAprendida leccion, CategoriaSubcategoria cat,VentanaPrincipal vent) {
        initComponents();
        categoria = cat;
        this.vent=vent;
        this.leccion = leccion;
        control = new LeccionController();

        if (leccion != null) {
            lecciones = control.leccionesDeLeccion(leccion.getId());
            indiceLeccionActual = -1;
            leccionActual = leccion;
        } else {
            almacenando = true;
        }
        leccionActual = leccion;

        cbProyecto.removeAllItems();
        List<Proyecto> listaPro = new ProyectoController().proyectos();

        for (Proyecto proyecto : listaPro) {
            cbProyecto.addItem(proyecto);
        }

        llenarCampos();
    }

    public void llenarCampos() {

        tfCat.setEditable(almacenando);
        tfIteracion.setEditable(almacenando);
        tfNombre.setEditable(almacenando);
        cbProyecto.setEditable(almacenando);
        tfPasos.setEditable(almacenando);
        tfReferencias.setEditable(almacenando);
        tfSolucion.setEditable(almacenando);
        tfUsuario.setEditable(almacenando);
        tfDescripcion.setEditable(almacenando);
        panelNav.setVisible(!almacenando);
        panelStore.setVisible(almacenando);

        if (almacenando == false) {



            tfCat.setText(leccionActual.getCategoriaSubcategoria().getNombre());
            tfIteracion.setText(leccionActual.getIteracion() + "");
            tfNombre.setText(leccionActual.getNombre());
            tfPasos.setText(leccionActual.getPasosSolucion());
            cbProyecto.setSelectedItem(leccionActual.getProyectoBean());
            tfReferencias.setText(leccionActual.getReferencias());
            tfSolucion.setText(leccionActual.getSolucion());
            tfUsuario.setText(leccionActual.getUsuario().getNickname());
            tfDescripcion.setText(leccionActual.getDescripcion());



        } else {
            tfCat.setText(categoria.getNombre());
        }
//        }else{
//            tfCat.setEditable(true);
//            tfIteracion.setEditable(true);
//            tfNombre.setEditable(true);
//            tfProyecto.setEditable(true);
//            tfPasos.setEditable(true);
//            tfReferencias.setEditable(true);
//            tfSolucion.setEditable(true);
//            tfUsuario.setEditable(true);
//        }

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        tfUsuario = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        tfIteracion = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        tfNombre = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tfSolucion = new javax.swing.JEditorPane();
        jScrollPane2 = new javax.swing.JScrollPane();
        tfPasos = new javax.swing.JEditorPane();
        jLabel7 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tfReferencias = new javax.swing.JEditorPane();
        panelNav = new javax.swing.JPanel();
        bReplay = new javax.swing.JButton();
        bAnterior = new javax.swing.JButton();
        bSiguiente = new javax.swing.JButton();
        bUltimo = new javax.swing.JButton();
        bPrimero = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        tfCat = new javax.swing.JTextField();
        panelStore = new javax.swing.JPanel();
        bGuardar = new javax.swing.JButton();
        bCancelar = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        tfDescripcion = new javax.swing.JEditorPane();
        cbProyecto = new javax.swing.JComboBox();

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel1.setText("Proyecto");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel2.setText("Usuario");

        tfUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfUsuarioActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel3.setText("Iteracion");

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel4.setText("Nombre ");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel5.setText("Solucion");

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel6.setText("Pasos Solucion");

        jScrollPane1.setViewportView(tfSolucion);

        jScrollPane2.setViewportView(tfPasos);

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel7.setText("Referencias");

        jScrollPane3.setViewportView(tfReferencias);

        bReplay.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/eam/gruposenior/gestorLEcciones/vista/imagenes/Add.png"))); // NOI18N
        bReplay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bReplayActionPerformed(evt);
            }
        });

        bAnterior.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/eam/gruposenior/gestorLEcciones/vista/imagenes/Back.png"))); // NOI18N
        bAnterior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bAnteriorActionPerformed(evt);
            }
        });

        bSiguiente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/eam/gruposenior/gestorLEcciones/vista/imagenes/Forward.png"))); // NOI18N
        bSiguiente.setText(">");
        bSiguiente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bSiguienteActionPerformed(evt);
            }
        });

        bUltimo.setText(">>");
        bUltimo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bUltimoActionPerformed(evt);
            }
        });

        bPrimero.setText("<<");
        bPrimero.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bPrimeroActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelNavLayout = new javax.swing.GroupLayout(panelNav);
        panelNav.setLayout(panelNavLayout);
        panelNavLayout.setHorizontalGroup(
            panelNavLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelNavLayout.createSequentialGroup()
                .addGap(166, 166, 166)
                .addComponent(bPrimero)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bAnterior)
                .addGap(18, 18, 18)
                .addComponent(bReplay)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(bSiguiente)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bUltimo)
                .addContainerGap(277, Short.MAX_VALUE))
        );
        panelNavLayout.setVerticalGroup(
            panelNavLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelNavLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelNavLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(bSiguiente, javax.swing.GroupLayout.DEFAULT_SIZE, 33, Short.MAX_VALUE)
                    .addComponent(bAnterior, javax.swing.GroupLayout.DEFAULT_SIZE, 33, Short.MAX_VALUE)
                    .addComponent(bReplay, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(bUltimo, javax.swing.GroupLayout.DEFAULT_SIZE, 33, Short.MAX_VALUE)
                    .addComponent(bPrimero, javax.swing.GroupLayout.DEFAULT_SIZE, 33, Short.MAX_VALUE))
                .addContainerGap())
        );

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel8.setText("Categoria");

        bGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/eam/gruposenior/gestorLEcciones/vista/imagenes/Select.png"))); // NOI18N
        bGuardar.setText("Guardar");
        bGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bGuardarActionPerformed(evt);
            }
        });

        bCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/eam/gruposenior/gestorLEcciones/vista/imagenes/Close.png"))); // NOI18N
        bCancelar.setText("Cancelar");
        bCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelStoreLayout = new javax.swing.GroupLayout(panelStore);
        panelStore.setLayout(panelStoreLayout);
        panelStoreLayout.setHorizontalGroup(
            panelStoreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelStoreLayout.createSequentialGroup()
                .addGap(169, 169, 169)
                .addComponent(bGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(342, Short.MAX_VALUE))
        );
        panelStoreLayout.setVerticalGroup(
            panelStoreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelStoreLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelStoreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(bCancelar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 33, Short.MAX_VALUE)
                    .addComponent(bGuardar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel9.setText("Descripcion");

        jScrollPane4.setViewportView(tfDescripcion);

        cbProyecto.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel8)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(tfNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 546, Short.MAX_VALUE)
                                .addGap(224, 224, 224))
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 770, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(tfUsuario, javax.swing.GroupLayout.DEFAULT_SIZE, 546, Short.MAX_VALUE)
                                    .addComponent(tfCat, javax.swing.GroupLayout.DEFAULT_SIZE, 546, Short.MAX_VALUE)
                                    .addComponent(cbProyecto, 0, 546, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tfIteracion, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 331, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 362, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 770, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(111, 111, 111)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(panelStore, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(panelNav, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(tfNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(tfCat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(9, 9, 9)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(tfUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(tfIteracion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cbProyecto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(panelNav, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(panelStore, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void tfUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfUsuarioActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfUsuarioActionPerformed

    private void bSiguienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bSiguienteActionPerformed
        if (almacenando == true) {
            return;
        }
        indiceLeccionActual++;
        if (indiceLeccionActual >= lecciones.size()) {
            indiceLeccionActual = lecciones.size() - 1;
            if(indiceLeccionActual>=0){
            leccionActual = lecciones.get(indiceLeccionActual);
            }
        } else {
            leccionActual = lecciones.get(indiceLeccionActual);
        }
        llenarCampos();
    }//GEN-LAST:event_bSiguienteActionPerformed

    private void bAnteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bAnteriorActionPerformed
        // TODO add your handling code here:
        if (almacenando == true) {
            return;
        }
        indiceLeccionActual--;
        if (indiceLeccionActual < 0) {
            indiceLeccionActual = -1;
            leccionActual = leccion;
        } else {
            leccionActual = lecciones.get(indiceLeccionActual);
        }
        llenarCampos();
    }//GEN-LAST:event_bAnteriorActionPerformed

    private void bPrimeroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bPrimeroActionPerformed
        // TODO add your handling code here:
        if (almacenando == true) {
            return;
        }
        leccionActual = leccion;
        llenarCampos();
    }//GEN-LAST:event_bPrimeroActionPerformed

    private void bUltimoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bUltimoActionPerformed
        // TODO add your handling code here:
        if (almacenando == true) {
            return;
        }
        leccionActual = lecciones.get(lecciones.size() - 1);
        indiceLeccionActual = lecciones.size() - 1;
        llenarCampos();
    }//GEN-LAST:event_bUltimoActionPerformed
    private boolean almacenando = false;
    private void bReplayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bReplayActionPerformed
        // TODO add your handling code here:
        tfCat.setText(leccion.getCategoriaSubcategoria().getNombre());
        tfIteracion.setText("");
        tfNombre.setText("");
        tfPasos.setText("");
        cbProyecto.setSelectedIndex(0);
        tfReferencias.setText("");
        tfSolucion.setText("");
        tfUsuario.setText(LogginManager.getUsuario().getNombreCompleto());
        tfDescripcion.setText("");
        almacenando = true;
        llenarCampos();

    }//GEN-LAST:event_bReplayActionPerformed

    private void bGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bGuardarActionPerformed
        // TODO add your handling code here:

        LeccionAprendida leccionNueva = new LeccionAprendida();
        if (categoria != null) {
            leccionNueva.setCategoriaSubcategoria(categoria);
        } else {
            leccionNueva.setCategoriaSubcategoria(leccion.getCategoriaSubcategoria());
        }
        leccionNueva.setDescripcion(tfDescripcion.getText());
        leccionNueva.setFecha(new Date());
        leccionNueva.setIteracion(Integer.parseInt(tfIteracion.getText()));
        leccionNueva.setLeccionPadre(leccion);
        leccionNueva.setNombre(tfNombre.getText());
        leccionNueva.setPasosSolucion(tfPasos.getText());
        leccionNueva.setProyectoBean((Proyecto) cbProyecto.getSelectedItem());
        leccionNueva.setReferencias(tfReferencias.getText());
        leccionNueva.setSolucion(tfSolucion.getText());
        leccionNueva.setUsuario(LogginManager.getUsuario());

        leccionActual=control.crearLeccion(leccionNueva);
        if(leccion==null){
        leccion = leccionActual;
        }

        lecciones = control.leccionesDeLeccion(leccion.getId());
        indiceLeccionActual = lecciones.size() - 1;
        if (indiceLeccionActual >= 0) {
            leccionActual = lecciones.get(indiceLeccionActual);
        }

        vent.actualizarArbol();



        almacenando = false;
        llenarCampos();
    }//GEN-LAST:event_bGuardarActionPerformed

    private void bCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bCancelarActionPerformed
        // TODO add your handling code here:
        if (indiceLeccionActual >= 0) {
            leccionActual = lecciones.get(indiceLeccionActual);
        } else {
            leccionActual = leccion;
        }
        almacenando = false;

        llenarCampos();
    }//GEN-LAST:event_bCancelarActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bAnterior;
    private javax.swing.JButton bCancelar;
    private javax.swing.JButton bGuardar;
    private javax.swing.JButton bPrimero;
    private javax.swing.JButton bReplay;
    private javax.swing.JButton bSiguiente;
    private javax.swing.JButton bUltimo;
    private javax.swing.JComboBox cbProyecto;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JPanel panelNav;
    private javax.swing.JPanel panelStore;
    private javax.swing.JTextField tfCat;
    private javax.swing.JEditorPane tfDescripcion;
    private javax.swing.JTextField tfIteracion;
    private javax.swing.JTextField tfNombre;
    private javax.swing.JEditorPane tfPasos;
    private javax.swing.JEditorPane tfReferencias;
    private javax.swing.JEditorPane tfSolucion;
    private javax.swing.JTextField tfUsuario;
    // End of variables declaration//GEN-END:variables
}
